-
Notifications
You must be signed in to change notification settings - Fork 745
/
URLTrackingControl.cs
258 lines (227 loc) · 12.8 KB
/
URLTrackingControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.UI.UserControls
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using Calendar = DotNetNuke.Common.Utilities.Calendar;
public abstract class URLTrackingControl : UserControlBase
{
// ReSharper disable InconsistentNaming
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label1;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label2;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label3;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label4;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label5;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label6;
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:FieldNamesMustBeginWithLowerCaseLetter", Justification = "Breaking Change")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label Label7;
// ReSharper restore InconsistentNaming
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected LinkButton cmdDisplay;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected HyperLink cmdEndCalendar;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected HyperLink cmdStartCalendar;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected DataGrid grdLog;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblClicks;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblCreatedDate;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblLastClick;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblLogURL;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblTrackingURL;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Label lblURL;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Panel pnlLog;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected Panel pnlTrack;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected TextBox txtEndDate;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected TextBox txtStartDate;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected CompareValidator valEndDate;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Breaking change")]
protected CompareValidator valStartDate;
private int moduleID = -2;
private string localResourceFile;
public string FormattedURL { get; set; } = string.Empty;
public string TrackingURL { get; set; } = string.Empty;
public string URL { get; set; } = string.Empty;
public int ModuleID
{
get
{
int moduleID = this.moduleID;
if (moduleID == -2)
{
if (this.Request.QueryString["mid"] != null)
{
int.TryParse(this.Request.QueryString["mid"], out moduleID);
}
}
return moduleID;
}
set
{
this.moduleID = value;
}
}
public string LocalResourceFile
{
get
{
string fileRoot;
if (string.IsNullOrEmpty(this.localResourceFile))
{
fileRoot = this.TemplateSourceDirectory + "/" + Localization.LocalResourceDirectory + "/URLTrackingControl.ascx";
}
else
{
fileRoot = this.localResourceFile;
}
return fileRoot;
}
set
{
this.localResourceFile = value;
}
}
/// <inheritdoc/>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.cmdDisplay.Click += this.CmdDisplay_Click;
try
{
// this needs to execute always to the client script code is registred in InvokePopupCal
this.cmdStartCalendar.NavigateUrl = Calendar.InvokePopupCal(this.txtStartDate);
this.cmdEndCalendar.NavigateUrl = Calendar.InvokePopupCal(this.txtEndDate);
if (!this.Page.IsPostBack)
{
if (!string.IsNullOrEmpty(this.URL))
{
this.lblLogURL.Text = this.URL; // saved for loading Log grid
TabType urlType = Globals.GetURLType(this.URL);
if (urlType == TabType.File && this.URL.StartsWith("fileid=", StringComparison.InvariantCultureIgnoreCase) == false)
{
// to handle legacy scenarios before the introduction of the FileServerHandler
var fileName = Path.GetFileName(this.URL);
var folderPath = this.URL.Substring(0, this.URL.LastIndexOf(fileName));
var folder = FolderManager.Instance.GetFolder(this.PortalSettings.PortalId, folderPath);
var file = FileManager.Instance.GetFile(folder, fileName);
this.lblLogURL.Text = "FileID=" + file.FileId;
}
var objUrls = new UrlController();
UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking(this.PortalSettings.PortalId, this.lblLogURL.Text, this.ModuleID);
if (objUrlTracking != null)
{
if (string.IsNullOrEmpty(this.FormattedURL))
{
this.lblURL.Text = Globals.LinkClick(this.URL, this.PortalSettings.ActiveTab.TabID, this.ModuleID, false);
if (!this.lblURL.Text.StartsWith("http") && !this.lblURL.Text.StartsWith("mailto"))
{
this.lblURL.Text = Globals.AddHTTP(this.Request.Url.Host) + this.lblURL.Text;
}
}
else
{
this.lblURL.Text = this.FormattedURL;
}
this.lblCreatedDate.Text = objUrlTracking.CreatedDate.ToString();
if (objUrlTracking.TrackClicks)
{
this.pnlTrack.Visible = true;
if (string.IsNullOrEmpty(this.TrackingURL))
{
if (!this.URL.StartsWith("http"))
{
this.lblTrackingURL.Text = Globals.AddHTTP(this.Request.Url.Host);
}
this.lblTrackingURL.Text += Globals.LinkClick(this.URL, this.PortalSettings.ActiveTab.TabID, this.ModuleID, objUrlTracking.TrackClicks);
}
else
{
this.lblTrackingURL.Text = this.TrackingURL;
}
this.lblClicks.Text = objUrlTracking.Clicks.ToString();
if (!Null.IsNull(objUrlTracking.LastClick))
{
this.lblLastClick.Text = objUrlTracking.LastClick.ToString();
}
}
if (objUrlTracking.LogActivity)
{
this.pnlLog.Visible = true;
this.txtStartDate.Text = DateTime.Today.AddDays(-6).ToShortDateString();
this.txtEndDate.Text = DateTime.Today.AddDays(1).ToShortDateString();
}
}
}
else
{
this.Visible = false;
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void CmdDisplay_Click(object sender, EventArgs e)
{
try
{
string strStartDate = this.txtStartDate.Text;
if (!string.IsNullOrEmpty(strStartDate))
{
strStartDate = strStartDate + " 00:00";
}
string strEndDate = this.txtEndDate.Text;
if (!string.IsNullOrEmpty(strEndDate))
{
strEndDate = strEndDate + " 23:59";
}
var objUrls = new UrlController();
// localize datagrid
Localization.LocalizeDataGrid(ref this.grdLog, this.LocalResourceFile);
this.grdLog.DataSource = objUrls.GetUrlLog(this.PortalSettings.PortalId, this.lblLogURL.Text, this.ModuleID, Convert.ToDateTime(strStartDate), Convert.ToDateTime(strEndDate));
this.grdLog.DataBind();
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
}
}